package com.wm.student;

import java.util.Arrays;

//学号(唯一）、姓名、年龄、性别、业余爱好
public class Student {
    private String id;
    private String name;
    private int age;
    private String strain;
    private String hobby;

    public Student() {
    }

    public Student(String id, String name, int age, String strain, String hobby) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.strain = strain;
        this.hobby = hobby;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getStrain() {
        return strain;
    }

    public void setStrain(String strain) {
        this.strain = strain;
    }

    public String getHobby() {
        return hobby;
    }

    public void setHobby(String hobby) {
        this.hobby = hobby;
    }
    public void print(){
        System.out.println("学号:" + this.getId() + ",姓名:" +this.getName()
                    + ",性别:" + this.getStrain() + ",年龄:" +this.getAge()
                    + ",兴趣爱好:" + this.getHobby());
    }
    Student[] stuList = new Student[1];
    public void add(Student student) {
        for (int i = 0; i < stuList.length; i++) {
            if (stuList[i] == null || stuList[i].equals("")) {
                stuList[i] = student;
                break;
            } else {
                stuList = Arrays.copyOf(stuList, (stuList.length + 1));
                continue;
            }
        }
    }
    public  void showName(){
        System.out.println("学生名单如下:");
        for (Student name: stuList ) {
            if (name!= null){
                System.out.println(name);
            }
        }
    }
    public boolean deleteName(String name){
        int j = -1;
        for (int i = 0; i < stuList.length ; i++) {
            if (stuList[i] != null && name.equals(stuList[i])){
                j = i;
                break;
            }
        }
        if(j != -1){
            //names[j]=null;
            for (int i = j; i < stuList.length-1; i++) {
                stuList[i] = stuList[i+1];
            }
            stuList[stuList.length-1] = null;
            return true;
        }else {
            return  false;
        }
    }

}